import { Component, OnInit } from "@angular/core";
import { CesiumMap } from "src/app/cesium-map/utils/cesiumMap";
import { InitCesiumService } from "src/app/cesium-map/services/InitCesiumService";
declare var Cesium;
@Component({
  selector: 'app-base-demo',
  templateUrl: './base-demo.component.html',
  styleUrls: ["./base-demo.component.less"],
})
export class BaseDemoComponent implements OnInit {
  list: any = [
    {
      id: 0,
      title: 'arcgis地图',
      server: 'ArcGisMapServerImageryProvider',
      par: {
        name: "img_arcgis",
        url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
      }
    },
    {
      id: 1,
      title: 'bing地图',
      par: {
        key: 'Av63hPkCmH18oGGn5Qg3QhLBJvknZ97xbhyw3utDLRtFv7anHjXNOUQbyWBL5fK5',
        url: "//dev.virtualearth.net"
      },
      server: 'BingMapsImageryProvider'
    },
    {
      id: 2,
      title: '高德影像',
      par: {
        url: "http://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}"
      },
      server: 'UrlTemplateImageryProvider'
    },
    {
      id: 3,
      title: '高德矢量',
      par: {
        url: "http://webst02.is.autonavi.com/appmaptile?style=7&x={x}&y={y}&z={z}"
      },
      server: 'UrlTemplateImageryProvider'
    },
    {
      id: 4,
      title: '天地地图',
      par: [
        {
          url: "http://t0.tianditu.com/img_w/wmts?tk=6ac4858482f0852842116eee4ff0574c",
          layer:'img',
          style:'default',
          tileMatrixSetID:'w',
          format:'tiles',
          maximumLevel: 18
      },
      {
        url: 'http://t0.tianditu.gov.cn/cia_w/wmts?tk=6ac4858482f0852842116eee4ff0574c',
        layer:'cia',
        style:'default',
        tileMatrixSetID:'w',
        format:'tiles',
        maximumLevel: 18
      },
      ],
      server: 'WebMapTileServiceImageryProvider'
    },
  ]

  selectedValue: any = null
  cesiumMap: CesiumMap;
  Viewer: any;
  params;
  lanTianOSGB;
  constructor(private InitCesiumService: InitCesiumService) { }


  ngOnInit() {
    this.cesiumMap = new CesiumMap();
  }

  /**
   * 底图切换
   */
  layerCut() {
    let layerPar: any={}
    this.list.forEach(element => {
      if (this.selectedValue == element.id) {
        layerPar =element
      }
    })
    if(this.selectedValue!=4){
      var img = new Cesium[`${layerPar['server']}`]({
        ...layerPar.par
      });
      this.addlayer(img)
    }else{
      layerPar.par.forEach(item=>{
        var img = new Cesium[`${layerPar['server']}`]({
          ...item
        });
        this.addlayer(img)
      })

    }
    

  }

  addlayer(img){
    var layers = this.Viewer.scene.imageryLayers;
    layers.addImageryProvider(img);
  }
  mapCreate($event) {
    this.Viewer = $event;

    // this.gohome();
  }

  /**
   * 回到视野
   */
  gohome() {
    console.log(211);
    this.Viewer.camera.flyTo({
      // fromDegrees()方法，将经纬度和高程转换为世界坐标
      destination: Cesium.Cartesian3.fromDegrees(
        111.60829020123631,
        23.453477687796436,
        1000
      ),
      orientation: {
        heading: 6, //代表镜头左右方向,正值为右,负值为左,360度和0度是一样的
        // 视角
        pitch: -0.3187528970141864, //俯视角，默认-90，垂直向下
        roll: 0, // 旋转角
      },
      duration: 5,
    });
  }
}
